<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" charset="utf-8">
        //惰性单体
        var Ext = {};
        Ext.Base = (function () {
                //私有变量，控制返回的单体对象
                var uniqInstance;
                function init() {
                    var a1 = true;
                    var a2 = 10;
                    var f1 = function () {
                        alert('f1');
                    };
                    var f2 = function () {
                        alert('f2');
                    };
                    return {
                        attr1:a1,
                        attr2:a2,
                        method1:function () {
                            f1();
                        },
                        method2:function () {
                            f2();
                        }
                    }
                }
                return {
                    getInstance:function () {
                        if(!uniqInstance){
                            uniqInstance = init();
                        }
                        return uniqInstance;
                    }

                }
            })();
        alert(Ext.Base.getInstance().attr1);
        Ext.Base.getInstance().method1();
    </script>
</head>
<body>
</body>
</html>